package com.scheuk.euler;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * The prime factors of 13195 are 5, 7, 13 and 29.
 * What is the largest prime factor of the number 600851475143 ?
 * Note: use 600851475143L
 * @author scheuk
 */
public class p003 {
	public static List<Integer> factors = new ArrayList<Integer>();

	public static int largestPrimeFactor(long number)
	{
		int i;
		for (i = 2; i <= number; i++)
		{
			if (number % i == 0)
			{
				factors.add(i);
				number /= i;
				i--;
			}
		}
		return i;
	}
	
	public static void main(String[] args)
	{
		long x = 600851475143L;
		int answer = largestPrimeFactor(x);
		System.out.println("factors: " + Arrays.toString(p003.factors.toArray()));
		System.out.println("answer: " + answer);
		System.out.printf("is prime? " + MathTools.isPrime(answer)); 
	}
}
